﻿using System.Collections.Generic;
using SiteUnity.Layers.Entity.General; 
using SiteUnity.Layers.Core.Provider.Users;
using SiteUnity.Layers.Entity.Users;
using SiteUnity.Layers.Entity.PageItems;
using SiteUnity.Frame.Common.Tools.Data;

namespace SiteUnity.Layers.Application.Users
{
    public class UserManager
    {
        static public User User
        {
            get
            {
                return Session.Get<User>("User");
            }
            set
            {
                Session.Add("User", value);
            }
        }

        static private UserProvider _userprovider = new UserProvider();

        public UserManager() { }

        static public User insertUser(User user, Website website)
        {
            return _userprovider.insertUser(user, website);
        }

        static public User insertUser(User user)
        {
            return insertUser(user, SiteManager.Website);
        }

        static public void insertCurrentUserPageItem(PageItem pageItem)
        {
            UserPageItem userPageItem = new UserPageItem();
            userPageItem.pageItemGuid = pageItem.Guid;
            userPageItem.userGuid = User.Guid;

            _userprovider.insertUserPageItem(userPageItem);
        }

        static public void insertUserPageItem(UserPageItem userPageItem)
        {
            _userprovider.insertUserPageItem(userPageItem);
        }

        static public List<User> getUserByPage(Page page)
        {
            return _userprovider.selectUserByPage(page);
        }

        static public List<User> getUserByPage()
        {
            return getUserByPage(SiteManager.Website.CurrentPage);
        }

        static public List<UserPageItem> getUserPageItemByPage(Page page)
        {
            return _userprovider.selectUserPageItemByPage(page);
        }

        static public List<UserPageItem> getUserPageItemByPage()
        {
            return getUserPageItemByPage(SiteManager.Website.CurrentPage);
        }
    }
}
